package service.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import dao.FlowerDao;
import dao.impl.FlowerDaoImpl;
import entity.Flower;
import service.FlowerService;
import vo.FlowerVO;

public class FlowerServiceImpl implements FlowerService {

	FlowerDao dao = new FlowerDaoImpl();
	
	@Override
	public List<FlowerVO> getFlowerByPage(int p) {
		// 准备好一个集合
		List<FlowerVO> listVo = new ArrayList<>();
		// 从数据库中查询
		List<Flower> list = dao.selectByPage(p);
		
		if (list.isEmpty()) {
			return Collections.emptyList();
		}else {
			// 循环倒腾
			for(Flower f : list) {
				FlowerVO fv = new FlowerVO();
				fv.setCode(f.getCode());
				fv.setName(f.getName());
				fv.setPrice(f.getPrice());
				fv.setScore(f.getScore());
				listVo.add(fv);
			}
			return listVo;
		}
	}

}
